package cn.zcx;

/**
 * description:interrupt()打断
 * author:zcx
 * lenovo
 * 时间：2022.02.07.19.52
 */
public class Ex2 {
    //方法一
    public  static volatile boolean exit=false;//退出标志

    public static void main(String[] args) {
        new Thread(){
            public void run(){
                System.out.println("线程启动");
                while (!exit){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("线程结束");
            }
        }.start();
        try {
            Thread.sleep(1000*5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        exit=true;
    }
}
